from typing import Optional

from pydantic import BaseModel, EmailStr, Field
from .base import BaseSchema


class UserRegister(BaseSchema):
    username: str = Field(default="zhaowenpeng",title="用户名", description="username")
    captcha_code: str = Field(default="1234",title="验证码", min_length=4, description="captcha_code")
    email: str = Field(default="zhaowenpeng@fifay.com",title="邮箱", description="email")
    password: str = Field(default='1qazxsw2',title="密码", min_length=8, description="password")
    # uuid: str = Field(..., title="uuid", description="uuid")
    # language: str = Field(..., title="语言", description="language")
    # country_code: str = Field(..., title="国家编码", description="country_code")
    # register_country: str = Field(..., title="注册国家", description="register_country")
    # invite_code: str = Field(..., title="邀请码", min_length=4, description="invite_code")


class UserLogin(BaseSchema):
    email: str = Field(..., title="邮箱", description="email")
    password: str = Field(..., title="密码", min_length=8, description="password")
    captcha_code: str = Field(..., title="验证码", min_length=4, description="captcha_code")


class CaptchaCode(BaseModel):
    email: EmailStr = Field(..., title="邮箱", description="email")


class UserSendActivateEmail(BaseSchema):
    email: str = Field(..., title="邮箱", description="email")


class UsernameCheck(BaseSchema):
    username: str = Field(..., title="用户名",max_length=32,description="用户名")



class UserActivate(BaseSchema):
    active_key: str = Field(..., title="激活码", description='active_key')
    email: str = Field(..., title="邮箱", description="email")


# Shared properties
class UserBase(BaseModel):
    email: Optional[EmailStr] = None
    is_active: Optional[bool] = True
    is_superuser: bool = False
    full_name: Optional[str] = None


# Properties to receive via API on creation
class UserCreate(UserBase):
    email: EmailStr
    password: str


# Properties to receive via API on update
class UserUpdate(UserBase):
    password: Optional[str] = None


class UserInDBBase(UserBase):
    id: Optional[int] = None

    class Config:
        orm_mode = True


# Additional properties to return via API
class User(UserInDBBase):
    pass


# Additional properties stored in DB
class UserInDB(BaseSchema):
    id: Optional[int] = None
    hashed_password: str
    email: str
